﻿function RightMenu(divid) {
    this.divid = divid;
    var _self = this;
    window.rightMenuStatus = true;
    this.backgroundColor = "rgb(224, 236, 255)";
    this.borderTop = "1px solid rgb(149, 184, 231)";
    this.borderLeft = "1px solid  rgb(149, 184, 231)";
    this.borderBottom = "1px solid  rgb(149, 184, 231)";
    this.borderRight = "1px solid  rgb(149, 184, 231)";
    this.MenuContent = [];
    this.AddItem = function (name, fn, img, checkicon, selecteded, singleselect) {
        this.MenuContent[this.MenuContent.length] = [name, fn, img, checkicon, selecteded, singleselect];
    }
    this.AddLine = function () {
        this.MenuContent[this.MenuContent.length] = "line";
    }
    this._div = null;
    this.Init = function () {
        var div = document.createElement("div");
        with (div.style) {
            position = "absolute";
            left = top = "0px";
            width = "150px";
            lineHeight = "20px";
            backgroundColor = this.backgroundColor;
            borderTop = this.borderTop;
            borderLeft = this.borderLeft;
            borderBottom = this.borderBottom;
            borderRight = this.borderRight;
            cursor = "default";
            zIndex = 9000001;
        }
        document.body.appendChild(div);
        var s = "";
        for (var i = 0; i < this.MenuContent.length; i++) {
            if (this.MenuContent[i] == "line") {
                s += "<div style=\"height:0px;line-height:0px;overflow:hidden;border-top:1px solid #888;border-bottom:1px solid #fff;\"></div>";
            }
            else {
                if (this.MenuContent[i][2]) {
                    s += "<div class='rmenu' id='id_" + this.MenuContent[i][0] + "' style=\"width:100%;\" hc=\"" + this.MenuContent[i][4] + "\" rel=\"" + this.MenuContent[i][5] + "\" selecteded=" + this.MenuContent[i][3] + " name=\"" + this.MenuContent[i][0] + "\" onclick=\"" + this.MenuContent[i][1] + "\" onmouseover=\"menuHover(this)\">&nbsp;<img alt=\"\" src=\"" + this.MenuContent[i][2] + "\" />&nbsp;&nbsp;&nbsp;" + this.MenuContent[i][0] + "</div>";
                }
                else {
                    s += "<div class='rmenu'  id='id_" + this.MenuContent[i][0] + "'  style=\"width:100%;\" hc=\"" + this.MenuContent[i][4] + "\" rel=\"" + this.MenuContent[i][5] + "\"  selecteded=" + this.MenuContent[i][3] + " name=\"" + this.MenuContent[i][0] + "\" onclick=\"" + this.MenuContent[i][1] + "\" onmouseover=\"style.background=\'#B6D2FF\';style.color=\'#fff\';\" >&nbsp;" + this.MenuContent[i][0] + "</div>";
                }
            }
            div.innerHTML = s;
            div.oW = div.offsetWidth;
            div.oH = div.offsetHeight;
            div.style.display = "none";
            var div1 = document.getElementById(_self.divid);
            div1.oncontextmenu = function (event) {
                event = event || window.event;
                var nx = document.body.scrollLeft + event.clientX;
                var ny = document.body.scrollTop + event.clientY;
                if (event.clientX + div.oW + 20 > document.body.offsetWidth) {
                    nx = nx - div.oW;
                }
                if (event.clientY + div.oH + 20 > document.body.offsetHeight) {
                    ny = ny - div.oH;
                }
                div.style.left = nx + "px";
                div.style.top = ny + "px";
                div.style.display = "block";
                $(document).click(function () {
                    div.style.display = "none";
                });
                $('div').click(function () {
                    div.style.display = "none";
                }
                );
                document.onclick = function () {
                    div.style.display = "none";
                    this.onclick = null;
                }
                return false;
            }
        }
        _self._div = div;
        return div;
    }
}